package com.briup.estore.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import com.briup.estore.bean.Customer;

import sun.misc.BASE64Encoder;

public class ExtUtils {

	/**
	 * md5加密，使用name+pwd加密
	 * 
	 * @param customer
	 * @return
	 * @throws Exception
	 */
	public static String ExtMD5(Customer customer) throws Exception {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
		byte[] digest = md5.digest((customer.getName() + customer.getPwd()).getBytes());
		BASE64Encoder encoder = new BASE64Encoder();

		return encoder.encode(digest);
	}

	public static List<String> checkCustomer(Customer customer) {

		List<String> list = new ArrayList<String>();
		if (StringUtils.isEmpty(customer.getName())) {
			list.add("name");
		}
		if (StringUtils.isEmpty(customer.getPwd())) {
			list.add("pwd");
		}
		if (StringUtils.isEmpty(customer.getZipcode())) {
			list.add("zipcode");
		}
		if (StringUtils.isEmpty(customer.getTelephone())) {
			list.add("telephone");
		}
		if (StringUtils.isEmpty(customer.getEmail())) {
			list.add("email");
		}
		if (list.size() > 0) {
			return list;
		}
		return null;
	}

	@Test
	public void test() throws Exception {
		Customer customer = new Customer();
		customer.setName("zqs");
		customer.setPwd("123456");
		System.out.println(ExtMD5(customer));
	}

}
